<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="com.lagou.webwork.model.Result" %>
<%@ page import="com.lagou.webwork.model.User" %><%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/5/26
  Time: 19:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员登陆</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link href="css/signin.css" rel="stylesheet">
</head>

<style>
    .bd-placeholder-img {
        font-size: 1.125rem;
        text-anchor: middle;
        -webkit-user-select: none;
        -moz-user-select: none;
        user-select: none;
    }

    @media (min-width: 768px) {
        .bd-placeholder-img-lg {
            font-size: 3.5rem;
        }
    }
</style>
<body class="text-center">
<main class="form-signin">
    <form action="/work/login" method="post">

        <%--        <input type="text" class="form-control" id="name" name="name" placeholder="请输入账号">--%>
        <%--        <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码">--%>


        <h1 class="h3 mb-3 fw-normal">请登录</h1>

        <div class="form-floating">
            <input type="text" class="form-control" id="name" name="name" placeholder="请输入账号">
            <%--            <label for="name">账号</label>--%>
        </div>
        <div class="form-floating">
            <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码">
            <%--            <label for="password">密码</label>--%>
        </div>

        <%--        <div class="checkbox mb-3">--%>
        <%--            <label>--%>
        <%--                <input type="checkbox" value="remember-me"> Remember me--%>
        <%--            </label>--%>
        <%--        </div>--%>
        <button type="submit" class="btn btn-lg btn-primary btn-block">登录</button>
    </form>
</main>


<!-- 提示-->
<div class="alert alert-danger" id="alterTips"
     style="width:400px;display: none;position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 99999;">

    <button type="button" class="close" aria-hidden="true" onclick="$('#alterTips').hide();">&times;</button>
    <p></p>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.help.js"></script>

<%
    Cookie[] cookies = request.getCookies();
    boolean isLogined = false;
    if (null!=cookies){
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals("userName")) {
                isLogined = true;
            }
        }
    }
    //判断有登陆过的cookie信息
    if (isLogined) {
%>
<script>
    alertTips("success", "登录成功!(3秒后自动跳转到管理页面)");
    setTimeout(function () {
        location.href = "/work/index.jsp";
    }, 3000);
</script>
<%
    }
%>

<%
    Result<User> resultModel = (Result<User>) request.getAttribute("resultModel");
    if (resultModel != null) {
        if (resultModel.getDataList() != null && resultModel.getDataList().size() > 0) {
//    request.getRequestDispatcher("/index.jsp").forward(request, response);
%>
<script>
    alertTips("success", "登录成功!(3秒后自动跳转到管理页面)");
    setTimeout(function () {
        location.href = "/work/index.jsp";
    }, 3000);
</script>

<%
} else {
%>
<script>
    alertTips("danger", "用户名或密码错误!");
</script>
<%
        }
    }
%>
</body>
</html>
